From 15cc20e7b5d46656b83a39f086650555e369aa1b Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Fri, 23 Feb 2018 14:59:49 -0500 Subject: [PATCH] Always include platform immodules No need to load these as gio modules, we just include them in libgtk. --- {modules/input => gtk}/gtk-text-input.xml | 0 .../gtkimcontextbroadway.c | 44 +---- gtk/gtkimcontextbroadway.h | 29 +++ {modules/input => gtk}/gtkimcontextime.c | 46 +---- {modules/input => gtk}/gtkimcontextime.h | 0 .../imquartz.c => gtk/gtkimcontextquartz.c | 47 +---- gtk/gtkimcontextquartz.h | 29 +++ .../imwayland.c => gtk/gtkimcontextwayland.c | 61 ++----- gtk/gtkimcontextwayland.h | 29 +++ {modules/input => gtk}/gtkimcontextxim.c | 169 +++++++----------- {modules/input => gtk}/gtkimcontextxim.h | 6 +- gtk/gtkimmodule.c | 56 ++++-- {modules/input => gtk}/imm-extra.h | 0 gtk/meson.build | 85 +++++---- meson.build | 1 - meson_options.txt | 6 - modules/input/meson.build | 118 ------------ modules/meson.build | 2 - 18 files changed, 286 insertions(+), 442 deletions(-) rename {modules/input => gtk}/gtk-text-input.xml (100%) rename modules/input/imbroadway.c => gtk/gtkimcontextbroadway.c (76%) create mode 100644 gtk/gtkimcontextbroadway.h rename {modules/input => gtk}/gtkimcontextime.c (97%) rename {modules/input => gtk}/gtkimcontextime.h (100%) rename modules/input/imquartz.c => gtk/gtkimcontextquartz.c (93%) create mode 100644 gtk/gtkimcontextquartz.h rename modules/input/imwayland.c => gtk/gtkimcontextwayland.c (94%) create mode 100644 gtk/gtkimcontextwayland.h rename {modules/input => gtk}/gtkimcontextxim.c (97%) rename {modules/input => gtk}/gtkimcontextxim.h (91%) rename {modules/input => gtk}/imm-extra.h (100%) delete mode 100644 modules/input/meson.build diff --git a/modules/input/gtk-text-input.xml b/gtk/gtk-text-input.xml similarity index 100% rename from modules/input/gtk-text-input.xml rename to gtk/gtk-text-input.xml diff --git a/modules/input/imbroadway.c b/gtk/gtkimcontextbroadway.c similarity index 76% rename from modules/input/imbroadway.c rename to gtk/gtkimcontextbroadway.c index 2fb40d471e..e8e459ada2 100644 --- a/modules/input/imbroadway.c +++ b/gtk/gtkimcontextbroadway.c @@ -21,7 +21,7 @@ #include "config.h" #include -#include +#include "gtk/gtkimcontextbroadway.h" #include "gtk/gtkintl.h" #include "gtk/gtkimmodule.h" @@ -42,38 +42,11 @@ typedef struct _GtkIMContextBroadwayClass GtkIMContextSimpleClass parent_class; } GtkIMContextBroadwayClass; -G_DEFINE_DYNAMIC_TYPE (GtkIMContextBroadway, gtk_im_context_broadway, GTK_TYPE_IM_CONTEXT_SIMPLE) - -void -g_io_module_load (GIOModule *module) -{ - g_type_module_use (G_TYPE_MODULE (module)); - - g_print ("load io module for broadway\n"); - gtk_im_context_broadway_register_type (G_TYPE_MODULE (module)); - - g_io_extension_point_implement (GTK_IM_MODULE_EXTENSION_POINT_NAME, - GTK_TYPE_IM_CONTEXT_BROADWAY, - "broadway", - 10); -} - -void -g_io_module_unload (GIOModule *module) -{ -} - -char ** -g_io_module_query (void) -{ - char *eps[] = { - GTK_IM_MODULE_EXTENSION_POINT_NAME, - NULL - }; - - return g_strdupv (eps); -} - +G_DEFINE_TYPE_WITH_CODE (GtkIMContextBroadway, gtk_im_context_broadway, GTK_TYPE_IM_CONTEXT_SIMPLE, + g_io_extension_point_implement (GTK_IM_MODULE_EXTENSION_POINT_NAME, + g_define_type_id, + "broadway", + 10)) static void broadway_set_client_widget (GtkIMContext *context, GtkWidget *widget) @@ -119,11 +92,6 @@ gtk_im_context_broadway_class_init (GtkIMContextBroadwayClass *class) klass->set_client_widget = broadway_set_client_widget; } -static void -gtk_im_context_broadway_class_finalize (GtkIMContextBroadwayClass *class) -{ -} - static void gtk_im_context_broadway_init (GtkIMContextBroadway *im_context) { diff --git a/gtk/gtkimcontextbroadway.h b/gtk/gtkimcontextbroadway.h new file mode 100644 index 0000000000..aacf60d9ce --- /dev/null +++ b/gtk/gtkimcontextbroadway.h @@ -0,0 +1,29 @@ +/* GTK - The GIMP Toolkit + * Copyright (C) 2000 Red Hat Software + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see . + */ + +#ifndef __GTK_IM_CONTEXT_BROADWAY_H__ +#define __GTK_IM_CONTEXT_BROADWAY_H__ + +#include + +G_BEGIN_DECLS + +GType gtk_im_context_broadway_get_type (void) G_GNUC_CONST; + +G_END_DECLS + +#endif /* __GTK_IM_CONTEXT_BROADWAY_H__ */ diff --git a/modules/input/gtkimcontextime.c b/gtk/gtkimcontextime.c similarity index 97% rename from modules/input/gtkimcontextime.c rename to gtk/gtkimcontextime.c index 212a17b669..7ba1483c29 100644 --- a/modules/input/gtkimcontextime.c +++ b/gtk/gtkimcontextime.c @@ -128,36 +128,11 @@ static void cb_client_widget_hierarchy_changed (GtkWidget *widget, #define GTK_TYPE_IM_CONTEXT_IME (gtk_im_context_ime_get_type ()) #define GTK_IM_CONTEXT_IME(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_IM_CONTEXT_IME, GtkIMContextIME)) -G_DEFINE_DYNAMIC_TYPE (GtkIMContextIME, gtk_im_context_ime, GTK_TYPE_IM_CONTEXT) - -void -g_io_module_load (GIOModule *module) -{ - g_type_module_use (G_TYPE_MODULE (module)); - - gtk_im_context_ime_register_type (G_TYPE_MODULE (module)); - - g_io_extension_point_implement (GTK_IM_MODULE_EXTENSION_POINT_NAME, - GTK_TYPE_IM_CONTEXT_IME, - "ime", - 10); -} - -void -g_io_module_unload (GIOModule *module) -{ -} - -char ** -g_io_module_query (void) -{ - char *eps[] = { - GTK_IM_MODULE_EXTENSION_POINT_NAME, - NULL - }; - - return g_strdupv (eps); -} +G_DEFINE_TYPE_WITH_CODE (GtkIMContextIME, gtk_im_context_ime, GTK_TYPE_IM_CONTEXT, + g_io_extension_point_implement (GTK_IM_MODULE_EXTENSION_POINT_NAME, + g_define_type_id, + "ime", + 10)) static void gtk_im_context_ime_class_init (GtkIMContextIMEClass *class) @@ -180,11 +155,6 @@ gtk_im_context_ime_class_init (GtkIMContextIMEClass *class) im_context_class->set_use_preedit = gtk_im_context_ime_set_use_preedit; } -static void -gtk_im_context_ime_class_finalize (GtkIMContextIMEClass *class) -{ -} - static void gtk_im_context_ime_init (GtkIMContextIME *context_ime) { @@ -512,7 +482,7 @@ get_utf8_preedit_string (GtkIMContextIME *context_ime, gint *pos_ret) g_warning ("%s", error->message); g_error_free (error); } - + if (pos_ret) { pos = ImmGetCompositionStringW (himc, GCS_CURSORPOS, NULL, 0); @@ -933,7 +903,7 @@ gtk_im_context_ime_set_preedit_font (GtkIMContext *context) /* Try to make sure we use a font that actually can show the * language in question. - */ + */ switch (PRIMARYLANGID (LOWORD (ime))) { @@ -970,7 +940,7 @@ gtk_im_context_ime_set_preedit_font (GtkIMContext *context) &font_desc, NULL); gtk_style_context_restore (style); - + if (lang[0]) { /* We know what language it is. Look for a character, any diff --git a/modules/input/gtkimcontextime.h b/gtk/gtkimcontextime.h similarity index 100% rename from modules/input/gtkimcontextime.h rename to gtk/gtkimcontextime.h diff --git a/modules/input/imquartz.c b/gtk/gtkimcontextquartz.c similarity index 93% rename from modules/input/imquartz.c rename to gtk/gtkimcontextquartz.c index 9d1a1cc9f8..2c950fc860 100644 --- a/modules/input/imquartz.c +++ b/gtk/gtkimcontextquartz.c @@ -21,7 +21,7 @@ #include "config.h" #include -#include +#include "gtk/gtkimcontextquartz.h" #include "gtk/gtkintl.h" #include "gtk/gtkimmodule.h" @@ -50,41 +50,11 @@ typedef struct _GtkIMContextQuartzClass GtkIMContextClass parent_class; } GtkIMContextQuartzClass; -G_DEFINE_DYNAMIC_TYPE (GtkIMContextQuartz, gtk_im_context_quartz, GTK_TYPE_IM_CONTEXT) - -void -g_io_module_load (GIOModule *module) -{ - g_type_module_use (G_TYPE_MODULE (module)); - - g_print ("load io module for quartz\n"); - gtk_im_context_quartz_register_type (G_TYPE_MODULE (module)); - - g_io_extension_point_implement (GTK_IM_MODULE_EXTENSION_POINT_NAME, - GTK_TYPE_IM_CONTEXT_BROADWAY, - "quartz", - 10); -} - -void -g_io_module_unload (GIOModule *module) -{ -} - -char ** -g_io_module_query (void) -{ - char *eps[] = { - GTK_IM_MODULE_EXTENSION_POINT_NAME, - NULL - }; - - return g_strdupv (eps); -} - - - - +G_DEFINE_TYPE_WITH_CODE (GtkIMContextQuartz, gtk_im_context_quartz, GTK_TYPE_IM_CONTEXT, + g_io_extension_point_implement (GTK_IM_MODULE_EXTENSION_POINT_NAME, + g_define_type_id, + "quartz", + 10)) static void quartz_get_preedit_string (GtkIMContext *context, @@ -396,11 +366,6 @@ gtk_im_context_quartz_class_init (GtkIMContextQuartzClass *class) object_class->finalize = imquartz_finalize; } -static void -gtk_im_context_quartz_class_finalize (GtkIMContextQuartzClass *class) -{ -} - static void gtk_im_context_quartz_init (GtkIMContextQuartz *qc) { diff --git a/gtk/gtkimcontextquartz.h b/gtk/gtkimcontextquartz.h new file mode 100644 index 0000000000..a051543c16 --- /dev/null +++ b/gtk/gtkimcontextquartz.h @@ -0,0 +1,29 @@ +/* GTK - The GIMP Toolkit + * Copyright (C) 2018 Red Hat Software + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see . + */ + +#ifndef __GTK_IM_CONTEXT_QUARTZ_H__ +#define __GTK_IM_CONTEXT_QUARTZ_H__ + +#include + +G_BEGIN_DECLS + +GType gtk_im_context_quartz_get_type (void) G_GNUC_CONST; + +G_END_DECLS + +#endif /* __GTK_IM_CONTEXT_QUARTZ_H__ */ diff --git a/modules/input/imwayland.c b/gtk/gtkimcontextwayland.c similarity index 94% rename from modules/input/imwayland.c rename to gtk/gtkimcontextwayland.c index 24f4f397dd..6ffd2885d3 100644 --- a/modules/input/imwayland.c +++ b/gtk/gtkimcontextwayland.c @@ -20,7 +20,7 @@ #include #include -#include +#include "gtk/gtkimcontextwayland.h" #include "gtk/gtkintl.h" #include "gtk/gtkimmodule.h" @@ -70,47 +70,15 @@ struct _GtkIMContextWayland guint use_preedit : 1; }; -static GtkIMContextWaylandGlobal *global = NULL; - -static void gtk_im_context_wayland_global_init (GdkDisplay *display); - -#define GTK_TYPE_IM_CONTEXT_WAYLAND (gtk_im_context_wayland_get_type ()) -#define GTK_IM_CONTEXT_WAYLAND(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_IM_CONTEXT_WAYLAND, GtkIMContextWayland)) - -G_DEFINE_DYNAMIC_TYPE (GtkIMContextWayland, gtk_im_context_wayland, GTK_TYPE_IM_CONTEXT_SIMPLE) - -void -g_io_module_load (GIOModule *module) -{ - g_type_module_use (G_TYPE_MODULE (module)); - - g_print ("load io module for wayland\n"); - gtk_im_context_wayland_register_type (G_TYPE_MODULE (module)); - gtk_im_context_wayland_global_init (gdk_display_get_default ()); - - g_io_extension_point_implement (GTK_IM_MODULE_EXTENSION_POINT_NAME, - GTK_TYPE_IM_CONTEXT_WAYLAND, - "wayland", - 10); -} - -void -g_io_module_unload (GIOModule *module) -{ -} - -char ** -g_io_module_query (void) -{ - char *eps[] = { - GTK_IM_MODULE_EXTENSION_POINT_NAME, - NULL - }; - - return g_strdupv (eps); -} +G_DEFINE_TYPE_WITH_CODE (GtkIMContextWayland, gtk_im_context_wayland, GTK_TYPE_IM_CONTEXT, + g_io_extension_point_implement (GTK_IM_MODULE_EXTENSION_POINT_NAME, + g_define_type_id, + "wayland", + 10)); +static GtkIMContextWaylandGlobal *global = NULL; +#define GTK_IM_CONTEXT_WAYLAND(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), gtk_im_context_wayland__get_type (), GtkIMContextWayland)) static void reset_preedit (GtkIMContextWayland *context) @@ -253,7 +221,7 @@ static const struct wl_registry_listener registry_listener = { static void gtk_im_context_wayland_global_init (GdkDisplay *display) { - if (global) + if (global != NULL) return; global = g_new0 (GtkIMContextWaylandGlobal, 1); @@ -356,6 +324,8 @@ translate_purpose (GtkInputPurpose purpose) return GTK_TEXT_INPUT_CONTENT_PURPOSE_PASSWORD; case GTK_INPUT_PURPOSE_PIN: return GTK_TEXT_INPUT_CONTENT_PURPOSE_PIN; + default: + g_assert_not_reached (); } return GTK_TEXT_INPUT_CONTENT_PURPOSE_NORMAL; @@ -487,7 +457,7 @@ gtk_im_context_wayland_get_preedit_string (GtkIMContext *context, gint *cursor_pos) { GtkIMContextWayland *context_wayland = GTK_IM_CONTEXT_WAYLAND (context); - gchar *preedit_str; + const char *preedit_str; GTK_IM_CONTEXT_CLASS (gtk_im_context_wayland_parent_class)->get_preedit_string (context, str, attrs, cursor_pos); @@ -632,11 +602,6 @@ gtk_im_context_wayland_class_init (GtkIMContextWaylandClass *klass) im_context_class->get_surrounding = gtk_im_context_wayland_get_surrounding; } -static void -gtk_im_context_wayland_class_finalize (GtkIMContextWaylandClass *class) -{ -} - static void on_content_type_changed (GtkIMContextWayland *context) { @@ -647,6 +612,8 @@ on_content_type_changed (GtkIMContextWayland *context) static void gtk_im_context_wayland_init (GtkIMContextWayland *context) { + gtk_im_context_wayland_global_init (gdk_display_get_default ()); + context->use_preedit = TRUE; g_signal_connect_swapped (context, "notify::input-purpose", G_CALLBACK (on_content_type_changed), context); diff --git a/gtk/gtkimcontextwayland.h b/gtk/gtkimcontextwayland.h new file mode 100644 index 0000000000..b3a75d3c02 --- /dev/null +++ b/gtk/gtkimcontextwayland.h @@ -0,0 +1,29 @@ +/* GTK - The GIMP Toolkit + * Copyright (C) 2018 Red Hat Software + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see . + */ + +#ifndef __GTK_IM_CONTEXT_WAYLAND_H__ +#define __GTK_IM_CONTEXT_WAYLAND_H__ + +#include + +G_BEGIN_DECLS + +GType gtk_im_context_wayland_get_type (void) G_GNUC_CONST; + +G_END_DECLS + +#endif /* __GTK_IM_CONTEXT_WAYLAND_H__ */ diff --git a/modules/input/gtkimcontextxim.c b/gtk/gtkimcontextxim.c similarity index 97% rename from modules/input/gtkimcontextxim.c rename to gtk/gtkimcontextxim.c index 03ce3e727c..c258df65c2 100644 --- a/modules/input/gtkimcontextxim.c +++ b/gtk/gtkimcontextxim.c @@ -20,8 +20,8 @@ #include #include -#include "gtkimmodule.h" #include "gtkimcontextxim.h" +#include "gtkimmodule.h" #include "gtk/gtkintl.h" @@ -52,7 +52,7 @@ struct _GtkIMContextXIM XIMFeedback *feedbacks; gint preedit_cursor; - + XIMCallback preedit_start_callback; XIMCallback preedit_done_callback; XIMCallback preedit_draw_callback; @@ -96,7 +96,7 @@ struct _GtkXIMInfo struct _StatusWindow { GtkWidget *window; - + /* Toplevel window to which the status window corresponds */ GtkWidget *toplevel; @@ -104,8 +104,6 @@ struct _StatusWindow GtkIMContextXIM *context; }; -static void gtk_im_context_xim_class_init (GtkIMContextXIMClass *class); -static void gtk_im_context_xim_init (GtkIMContextXIM *im_context_xim); static void gtk_im_context_xim_finalize (GObject *obj); static void gtk_im_context_xim_set_client_widget (GtkIMContext *context, GtkWidget *widget); @@ -146,37 +144,11 @@ static void xim_info_display_closed (GdkDisplay *display, gboolean is_error, GtkXIMInfo *info); -G_DEFINE_DYNAMIC_TYPE (GtkIMContextXIM, gtk_im_context_xim, GTK_TYPE_IM_CONTEXT) - -void -g_io_module_load (GIOModule *module) -{ - g_type_module_use (G_TYPE_MODULE (module)); - - g_print ("load io module for x11\n"); - gtk_im_context_xim_register_type (G_TYPE_MODULE (module)); - - g_io_extension_point_implement (GTK_IM_MODULE_EXTENSION_POINT_NAME, - GTK_TYPE_IM_CONTEXT_XIM, - "xim", - 10); -} - -void -g_io_module_unload (GIOModule *module) -{ -} - -char ** -g_io_module_query (void) -{ - char *eps[] = { - GTK_IM_MODULE_EXTENSION_POINT_NAME, - NULL - }; - - return g_strdupv (eps); -} +G_DEFINE_TYPE_WITH_CODE (GtkIMContextXIM, gtk_im_context_xim, GTK_TYPE_IM_CONTEXT, + g_io_extension_point_implement (GTK_IM_MODULE_EXTENSION_POINT_NAME, + g_define_type_id, + "xim", + 10)) static GSList *open_ims = NULL; @@ -190,11 +162,11 @@ static GSList *status_windows = NULL; #define ALLOWED_MASK (XIMPreeditCallbacks | XIMPreeditNothing | XIMPreeditNone | \ XIMStatusCallbacks | XIMStatusNothing | XIMStatusNone) -static XIMStyle -choose_better_style (XIMStyle style1, XIMStyle style2) +static XIMStyle +choose_better_style (XIMStyle style1, XIMStyle style2) { - XIMStyle s1, s2, u; - + XIMStyle s1, s2, u; + if (style1 == 0) return style2; if (style2 == 0) return style1; if ((style1 & (PREEDIT_MASK | STATUS_MASK)) @@ -292,7 +264,7 @@ setup_im (GtkXIMInfo *info) if (ic_values) { int i; - + for (i = 0; i < ic_values->count_values; i++) if (strcmp (ic_values->supported_values[i], XNStringConversionCallback) == 0) @@ -307,7 +279,7 @@ setup_im (GtkXIMInfo *info) for (i = 0; i < xim_styles->count_styles; i++) g_print ("%#x\n", xim_styles->supported_styles[i]); #endif - + XFree (ic_values); } @@ -421,7 +393,7 @@ xim_destroy_callback (XIM xim, reinitialize_all_ics (info); xim_info_try_im (info); return; -} +} static GtkXIMInfo * get_im (GdkWindow *client_window, @@ -492,11 +464,6 @@ gtk_im_context_xim_class_init (GtkIMContextXIMClass *class) gobject_class->finalize = gtk_im_context_xim_finalize; } -static void -gtk_im_context_xim_class_finalize (GtkIMContextXIMClass *class) -{ -} - static void gtk_im_context_xim_init (GtkIMContextXIM *im_context_xim) { @@ -514,7 +481,7 @@ gtk_im_context_xim_finalize (GObject *obj) context_xim->finalizing = TRUE; - if (context_xim->im_info && !context_xim->im_info->ics->next) + if (context_xim->im_info && !context_xim->im_info->ics->next) { if (context_xim->im_info->reconnecting) { @@ -562,7 +529,7 @@ reinitialize_ic (GtkIMContextXIM *context_xim) g_signal_emit_by_name (context_xim, "preedit-changed"); } } - /* + /* reset filter_key_release flag, otherwise keystrokes will be doubled until reconnecting to XIM. */ @@ -579,7 +546,7 @@ set_ic_client_window (GtkIMContextXIM *context_xim, context_xim->im_info->ics = g_slist_remove (context_xim->im_info->ics, context_xim); context_xim->im_info = NULL; } - + context_xim->client_window = client_window; context_xim->client_window_xid = None; @@ -599,7 +566,7 @@ set_ic_client_window (GtkIMContextXIM *context_xim, } } } - + update_client_widget (context_xim); } @@ -624,7 +591,7 @@ gtk_im_context_xim_new (void) result = g_object_new (GTK_TYPE_IM_CONTEXT_XIM, NULL); result->locale = g_strdup (setlocale (LC_CTYPE, NULL)); - + g_get_charset (&charset); result->mb_charset = g_strdup (charset); @@ -651,7 +618,7 @@ mb_to_utf8 (GtkIMContextXIM *context_xim, g_error_free (error); } } - + return result; } @@ -696,12 +663,12 @@ gtk_im_context_xim_filter_keypress (GtkIMContext *context, xevent.state = state; xevent.keycode = gdk_event_get_scancode ((GdkEvent *) event); xevent.same_screen = True; - + if (XFilterEvent ((XEvent *)&xevent, context_xim->client_window_xid)) return TRUE; - + if (state & - (gtk_accelerator_get_default_mod_mask () & ~(GDK_SHIFT_MASK | GDK_CONTROL_MASK))) + (gtk_accelerator_get_default_mod_mask () & ~(GDK_SHIFT_MASK | GDK_CONTROL_MASK))) return FALSE; again: @@ -716,7 +683,7 @@ gtk_im_context_xim_filter_keypress (GtkIMContext *context, if (status == XBufferOverflow) { buffer_size = num_bytes; - if (buffer != static_buffer) + if (buffer != static_buffer) g_free (buffer); buffer = g_malloc (num_bytes + 1); goto again; @@ -743,12 +710,12 @@ gtk_im_context_xim_filter_keypress (GtkIMContext *context, g_signal_emit_by_name (context, "commit", result_utf8); result = TRUE; } - + g_free (result_utf8); } } - if (buffer != static_buffer) + if (buffer != static_buffer) g_free (buffer); return result; @@ -765,7 +732,7 @@ gtk_im_context_xim_focus_in (GtkIMContext *context) context_xim->has_focus = TRUE; update_status_window (context_xim); - + if (ic) XSetICFocus (ic); } @@ -781,10 +748,10 @@ gtk_im_context_xim_focus_out (GtkIMContext *context) if (context_xim->has_focus) { XIC ic = gtk_im_context_xim_get_ic (context_xim); - + context_xim->has_focus = FALSE; update_status_window (context_xim); - + if (ic) XUnsetICFocus (ic); } @@ -850,7 +817,7 @@ gtk_im_context_xim_reset (GtkIMContext *context) if (!ic) return; - + if (context_xim->preedit_length == 0) return; @@ -908,7 +875,7 @@ add_feedback_attr (PangoAttrList *attrs, gint end_pos) { PangoAttribute *attr; - + gint start_index = g_utf8_offset_to_pointer (str, start_pos) - str; gint end_index = g_utf8_offset_to_pointer (str, end_pos) - str; @@ -940,7 +907,7 @@ add_feedback_attr (PangoAttrList *attrs, g_warning ("Unrendered feedback style: %#lx", feedback & ~FEEDBACK_MASK); } -static void +static void gtk_im_context_xim_get_preedit_string (GtkIMContext *context, gchar **str, PangoAttrList **attrs, @@ -954,7 +921,7 @@ gtk_im_context_xim_get_preedit_string (GtkIMContext *context, int i; XIMFeedback last_feedback = 0; gint start = -1; - + *attrs = pango_attr_list_new (); for (i = 0; i < context_xim->preedit_length; i++) @@ -964,7 +931,7 @@ gtk_im_context_xim_get_preedit_string (GtkIMContext *context, { if (start >= 0) add_feedback_attr (*attrs, utf8, last_feedback, start, i); - + last_feedback = new_feedback; start = i; } @@ -990,12 +957,12 @@ preedit_start_callback (XIC xic, { GtkIMContext *context = GTK_IM_CONTEXT (client_data); GtkIMContextXIM *context_xim = GTK_IM_CONTEXT_XIM (context); - + if (!context_xim->finalizing) g_signal_emit_by_name (context, "preedit-start"); return -1; /* No length limit */ -} +} static void preedit_done_callback (XIC xic, @@ -1014,7 +981,7 @@ preedit_done_callback (XIC xic, if (!context_xim->finalizing) g_signal_emit_by_name (context, "preedit-end"); -} +} static gint xim_text_to_utf8 (GtkIMContextXIM *context, XIMText *xim_text, gchar **text) @@ -1040,11 +1007,11 @@ xim_text_to_utf8 (GtkIMContextXIM *context, XIMText *xim_text, gchar **text) "UTF-8", context->mb_charset, NULL, NULL, &error); - + if (result) { text_length = g_utf8_strlen (result, -1); - + if (text_length != xim_text->length) { g_warning ("Size mismatch when converting text from input method: supplied length = %d\n, result length = %d", xim_text->length, text_length); @@ -1070,7 +1037,7 @@ xim_text_to_utf8 (GtkIMContextXIM *context, XIMText *xim_text, gchar **text) } static void -preedit_draw_callback (XIC xic, +preedit_draw_callback (XIC xic, XPointer client_data, XIMPreeditDrawCallbackStruct *call_data) { @@ -1083,12 +1050,12 @@ preedit_draw_callback (XIC xic, gint diff; gint new_length; gchar *tmp; - + gint chg_first = CLAMP (call_data->chg_first, 0, context->preedit_length); gint chg_length = CLAMP (call_data->chg_length, 0, context->preedit_length - chg_first); context->preedit_cursor = call_data->caret; - + if (chg_first != call_data->chg_first || chg_length != call_data->chg_length) g_warning ("Invalid change to preedit string, first=%d length=%d (orig length == %d)", call_data->chg_first, call_data->chg_length, context->preedit_length); @@ -1099,7 +1066,7 @@ preedit_draw_callback (XIC xic, new_text = g_utf8_to_ucs4_fast (tmp, -1, NULL); g_free (tmp); } - + diff = new_text_length - chg_length; new_length = context->preedit_length + diff; @@ -1140,7 +1107,7 @@ preedit_draw_callback (XIC xic, if (!context->finalizing) g_signal_emit_by_name (context, "preedit-changed"); } - + static void preedit_caret_callback (XIC xic, @@ -1148,7 +1115,7 @@ preedit_caret_callback (XIC xic, XIMPreeditCaretCallbackStruct *call_data) { GtkIMContextXIM *context = GTK_IM_CONTEXT_XIM (client_data); - + if (call_data->direction == XIMAbsolutePosition) { context->preedit_cursor = call_data->position; @@ -1160,7 +1127,7 @@ preedit_caret_callback (XIC xic, g_warning ("Caret movement command: %d %d %d not supported", call_data->position, call_data->direction, call_data->style); } -} +} static void status_start_callback (XIC xic, @@ -1168,7 +1135,7 @@ status_start_callback (XIC xic, XPointer call_data) { return; -} +} static void status_done_callback (XIC xic, @@ -1341,7 +1308,7 @@ set_status_callback (GtkIMContextXIM *context_xim) context_xim->status_done_callback.callback = (XIMProc)status_done_callback; context_xim->status_draw_callback.client_data = (XPointer)context_xim; context_xim->status_draw_callback.callback = (XIMProc)status_draw_callback; - + return XVaCreateNestedList (0, XNStatusStartCallback, &context_xim->status_start_callback, XNStatusDoneCallback, &context_xim->status_done_callback, @@ -1355,10 +1322,10 @@ set_string_conversion_callback (GtkIMContextXIM *context_xim, XIC xic) { if (!context_xim->im_info->supports_string_conversion) return; - + context_xim->string_conversion_callback.client_data = (XPointer)context_xim; context_xim->string_conversion_callback.callback = (XIMProc)string_conversion_callback; - + XSetICValues (xic, XNStringConversionCallback, (XPointer)&context_xim->string_conversion_callback, @@ -1437,11 +1404,11 @@ gtk_im_context_xim_get_ic (GtkIMContextXIM *context_xim) context_xim->filter_key_release = (mask & KeyReleaseMask) != 0; set_string_conversion_callback (context_xim, xic); } - + context_xim->ic = xic; update_status_window (context_xim); - + if (xic && context_xim->has_focus) XSetICFocus (xic); } @@ -1493,7 +1460,7 @@ disclaim_status_window (GtkIMContextXIM *context_xim) g_assert (context_xim->status_window->context == context_xim); status_window_set_text (context_xim->status_window, ""); - + context_xim->status_window->context = NULL; context_xim->status_window = NULL; } @@ -1540,7 +1507,7 @@ update_in_toplevel (GtkIMContextXIM *context_xim) if (context_xim->client_widget) { GtkWidget *toplevel = gtk_widget_get_toplevel (context_xim->client_widget); - + context_xim->in_toplevel = (toplevel && gtk_widget_is_toplevel (toplevel)); } else @@ -1549,7 +1516,7 @@ update_in_toplevel (GtkIMContextXIM *context_xim) /* Some paranoia, in case we don't get a focus out */ if (!context_xim->in_toplevel) context_xim->has_focus = FALSE; - + update_status_window (context_xim); } @@ -1679,7 +1646,7 @@ status_window_free (StatusWindow *status_window) if (status_window->context) status_window->context->status_window = NULL; - + g_signal_handlers_disconnect_by_func (status_window->toplevel, G_CALLBACK (on_status_toplevel_destroy), status_window); @@ -1692,9 +1659,9 @@ status_window_free (StatusWindow *status_window) if (status_window->window) gtk_widget_destroy (status_window->window); - + g_object_set_data (G_OBJECT (status_window->toplevel), "gtk-im-xim-status-window", NULL); - + g_free (status_window); } @@ -1708,7 +1675,7 @@ status_window_get (GtkWidget *toplevel) status_window = g_object_get_data (G_OBJECT (toplevel), "gtk-im-xim-status-window"); if (status_window) return status_window; - + status_window = g_new0 (StatusWindow, 1); status_window->toplevel = toplevel; @@ -1723,7 +1690,7 @@ status_window_get (GtkWidget *toplevel) g_signal_connect (toplevel, "notify::display", G_CALLBACK (on_status_toplevel_notify_display), status_window); - + g_object_set_data (G_OBJECT (toplevel), "gtk-im-xim-status-window", status_window); return status_window; @@ -1737,7 +1704,7 @@ status_window_make_window (StatusWindow *status_window) { GtkWidget *window; GtkWidget *status_label; - + status_window->window = gtk_window_new (GTK_WINDOW_POPUP); window = status_window->window; @@ -1746,9 +1713,9 @@ status_window_make_window (StatusWindow *status_window) status_label = gtk_label_new (""); g_object_set (status_label, "margin", 1, NULL); gtk_widget_show (status_label); - + gtk_container_add (GTK_CONTAINER (window), status_label); - + gtk_window_set_display (GTK_WINDOW (status_window->window), gtk_widget_get_display (status_window->toplevel)); @@ -1765,13 +1732,13 @@ status_window_set_text (StatusWindow *status_window, if (text[0]) { GtkWidget *label; - + if (!status_window->window) status_window_make_window (status_window); - + label = gtk_bin_get_child (GTK_BIN (status_window->window)); gtk_label_set_text (GTK_LABEL (label), text); - + gtk_widget_show (status_window->window); } else @@ -1783,7 +1750,7 @@ status_window_set_text (StatusWindow *status_window, /** * gtk_im_context_xim_shutdown: - * + * * Destroys all the status windows that are kept by the XIM contexts. This * function should only be called by the XIM module exit routine. **/ diff --git a/modules/input/gtkimcontextxim.h b/gtk/gtkimcontextxim.h similarity index 91% rename from modules/input/gtkimcontextxim.h rename to gtk/gtkimcontextxim.h index d81a7ff2d1..5965c65b00 100644 --- a/modules/input/gtkimcontextxim.h +++ b/gtk/gtkimcontextxim.h @@ -39,9 +39,9 @@ struct _GtkIMContextXIMClass GtkIMContextClass parent_class; }; -GtkIMContext *gtk_im_context_xim_new (void); - -void gtk_im_context_xim_shutdown (void); +GType gtk_im_context_xim_get_type (void) G_GNUC_CONST; +GtkIMContext *gtk_im_context_xim_new (void); +void gtk_im_context_xim_shutdown (void); G_END_DECLS diff --git a/gtk/gtkimmodule.c b/gtk/gtkimmodule.c index 021b5c10b5..5e45bd8cfb 100644 --- a/gtk/gtkimmodule.c +++ b/gtk/gtkimmodule.c @@ -42,18 +42,27 @@ #ifdef GDK_WINDOWING_X11 #include "x11/gdkx.h" +#include "gtkimcontextxim.h" #endif #ifdef GDK_WINDOWING_WAYLAND #include "wayland/gdkwayland.h" +#include "gtkimcontextwayland.h" #endif #ifdef GDK_WINDOWING_BROADWAY #include "broadway/gdkbroadway.h" +#include "gtkimcontextbroadway.h" #endif #ifdef GDK_WINDOWING_WIN32 #include "win32/gdkwin32.h" +#include "gtkimcontextime.h" +#endif + +#ifdef GDK_WINDOWING_QUARTZ +#include "quartz/gdkquartz.h" +#include "gtkimcontextquartz.h" #endif #ifdef G_OS_WIN32 @@ -101,6 +110,7 @@ is_platform (const char *context_id) return g_strcmp0 (context_id, "wayland") == 0 || g_strcmp0 (context_id, "broadway") == 0 || g_strcmp0 (context_id, "xim") == 0 || + g_strcmp0 (context_id, "quartz") == 0 || g_strcmp0 (context_id, "ime") == 0; } @@ -127,6 +137,11 @@ match_backend (const char *context_id) return GDK_IS_WIN32_DISPLAY (gdk_display_get_default ()); #endif +#ifdef GDK_WINDOWING_QUARTZ + if (g_strcmp0 (context_id, "quartz") == 0) + return GDK_IS_QUARTZ_DISPLAY (gdk_display_get_default ()); +#endif + return TRUE; } @@ -236,7 +251,21 @@ gtk_im_modules_init (void) g_io_extension_point_set_required_type (ep, GTK_TYPE_IM_CONTEXT); g_type_ensure (gtk_im_context_simple_get_type ()); - // other builtin im context types go here +#ifdef GDK_WINDOWING_X11 + g_type_ensure (gtk_im_context_xim_get_type ()); +#endif +#ifdef GDK_WINDOWING_WAYLAND + g_type_ensure (gtk_im_context_wayland_get_type ()); +#endif +#ifdef GDK_WINDOWING_BROADWAY + g_type_ensure (gtk_im_context_broadway_get_type ()); +#endif +#ifdef GDK_WINDOWING_WIN32 + g_type_ensure (gtk_im_context_ime_get_type ()); +#endif +#ifdef GDK_WINDOWING_QUARTZ + g_type_ensure (gtk_im_context_quartz_get_type ()); +#endif scope = g_io_module_scope_new (G_IO_MODULE_SCOPE_BLOCK_DUPLICATES); @@ -251,16 +280,17 @@ gtk_im_modules_init (void) g_io_module_scope_free (scope); - { - GList *list, *l; - - list = g_io_extension_point_get_extensions (ep); - for (l = list; l; l = l->next) - { - GIOExtension *ext = l->data; - g_print ("extension: %s: type %s\n", - g_io_extension_get_name (ext), - g_type_name (g_io_extension_get_type (ext))); - } - } + if (GTK_DEBUG_CHECK (MODULES)) + { + GList *list, *l; + + list = g_io_extension_point_get_extensions (ep); + for (l = list; l; l = l->next) + { + GIOExtension *ext = l->data; + g_print ("extension: %s: type %s\n", + g_io_extension_get_name (ext), + g_type_name (g_io_extension_get_type (ext))); + } + } } diff --git a/modules/input/imm-extra.h b/gtk/imm-extra.h similarity index 100% rename from modules/input/imm-extra.h rename to gtk/imm-extra.h diff --git a/gtk/meson.build b/gtk/meson.build index 58af3bebbf..43e3c1daaa 100644 --- a/gtk/meson.build +++ b/gtk/meson.build @@ -578,6 +578,48 @@ install_headers(gtk_public_headers, subdir: 'gtk-4.0/gtk/') gtk_sources = gtk_public_sources + gtk_private_sources +proto_sources = [ + ['gtk-text-input', 'stable', ], +] + +im_wayland_sources = files('gtkimcontextwayland.c') +wayland_scanner = find_program('wayland-scanner') +genprotocols = find_program('../gdk/wayland/genprotocolfiles.py') + +foreach p: proto_sources + proto_name = p.get(0) + proto_stability = p.get(1) + + if proto_stability == 'stable' + output_base = proto_name + input = '@0@.xml'.format(proto_name) + else + proto_version = p.get(2) + output_base = '@0@-@1@-@2@'.format(proto_name, proto_stability, proto_version) + input = join_paths(proto_dir, '@0@/@1@/@2@.xml'.format(proto_stability, proto_name, output_base)) + endif + + im_wayland_sources += custom_target('@0@ client header'.format(output_base), + input: input, + output: '@0@-client-protocol.h'.format(output_base), + command: [ + genprotocols, + wayland_scanner, + '@INPUT@', '@OUTPUT@', + 'client-header', + ]) + + im_wayland_sources += custom_target('@0@ source'.format(output_base), + input: input, + output: '@0@-protocol.c'.format(output_base), + command: [ + genprotocols, + wayland_scanner, + '@INPUT@', '@OUTPUT@', + 'code', + ]) +endforeach + if os_unix gtk_unix_print_headers = [ 'gtkpagesetupunixdialog.h', @@ -616,6 +658,7 @@ if os_win32 ]) gtk_sources += gtk_win32_print_sources + gtk_sources += ['gtkimcontextime.c'] if cc.has_header_symbol('windows.h', 'IPrintDialogCallback') cdata.set('HAVE_IPRINTDIALOGCALLBACK', 1) @@ -624,10 +667,12 @@ endif if x11_enabled gtk_sources += ['gtkapplication-x11.c', 'gtkmountoperation-x11.c'] + gtk_sources += ['gtkimcontextxim.c'] endif if wayland_enabled gtk_sources += ['gtkapplication-wayland.c'] + gtk_sources += im_wayland_sources endif if x11_enabled or wayland_enabled @@ -647,6 +692,8 @@ if quartz_enabled 'gtkfilechoosernativequartz.c', 'gtkquartz.c', ]) + gtk_sources += ['gtkimcontextquartz.c'] + gtk_cargs += ['-xobjective-c'] # FIXME? maybe add_languages() instead? endif @@ -824,6 +871,10 @@ if wayland_enabled gtk_sources += gtk_wayland_sources endif +if broadway_enabled + gtk_sources += ['gtkimcontextbroadway.c'] +endif + if win32_enabled gtk_cargs += ['-DGTK_PRINT_BACKENDS="file,lpr"'] gtk_deps += [ giowin32_dep ] @@ -868,39 +919,6 @@ if cc.has_header('langinfo.h') endforeach endif -# Input methods - -gen_headers = [ gtk_gen_headers, gsk_gen_headers, gdk_gen_headers, ] - -included_input_modules = [] -foreach m: inc_im_method_defs # populated in modules/input/meson.build - im_name = m[0] - im_srcs = m[1] - im_args = m[2] - im_libs = m[3] - - included_input_modules += static_library('im-@0@'.format(im_name), - im_srcs, gen_headers, - c_args: im_args, - include_directories: [confinc, gdkinc, gtkinc], - dependencies: gtk_deps + im_libs) -endforeach - -foreach m: dyn_im_method_defs # populated in modules/input/meson.build - im_name = m[0] - im_srcs = m[1] - im_args = m[2] - im_libs = m[3] - - shared_module('libim-@0@'.format(im_name), im_srcs, gen_headers, - c_args: im_args, - include_directories: [confinc, gdkinc, gtkinc], - dependencies: gtk_deps + im_libs, - name_prefix: '', # we want im-foo.so not libim-foo.so - install_dir: immodules_install_dir, - install: true) -endforeach - # Library libgtk = shared_library('gtk-4', soversion: gtk_soversion, @@ -909,7 +927,6 @@ libgtk = shared_library('gtk-4', include_directories: [confinc, gdkinc, gskinc, gtkinc], dependencies: gtk_deps + [libgdk_dep, libgsk_dep], link_with: [libgdk, libgsk, ], - link_whole: included_input_modules, link_args: common_ldflags, install: true) diff --git a/meson.build b/meson.build index b778b5fa8e..d50d2f222e 100644 --- a/meson.build +++ b/meson.build @@ -589,7 +589,6 @@ if cloudproviders_enabled endif endif -subdir('modules/input') subdir('gdk') subdir('gsk') subdir('gtk') diff --git a/meson_options.txt b/meson_options.txt index 0c34a1fdbb..74e5f21b32 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -24,12 +24,6 @@ option('print-backends', type : 'string', value : 'cups,file', option('colord', type: 'combo', choices : ['yes', 'no', 'auto'], value : 'auto', description : 'Build colord support for the CUPS printing backend') -# Modules -option('dynamic-modules', type: 'boolean', value : true, - description : 'Allow dynamic module loading') -option('included-immodules', type: 'string', value : 'none', - description : 'Build the specified input methods (comma-separated list, "all", or "none")') - # Documentation and introspection option('documentation', type: 'boolean', value: 'false', description : 'Build API reference and tools documentation') diff --git a/modules/input/meson.build b/modules/input/meson.build deleted file mode 100644 index ae904b8e8d..0000000000 --- a/modules/input/meson.build +++ /dev/null @@ -1,118 +0,0 @@ -# Note: this file is included from the top-level before gtk/meson.build. -# The actual input modules are then built in gtk/meson.build based on the -# defs we provide here. It has to be that way because included input methods -# need to be built before libgtk-4.so is built, so before gtk/meson.build, but -# all input methods also rely on gtk generated headers to be created first, so -# there is a bit of an ordering problem which we solve by collecting all the -# information here but moving the actual build definitions to gtk/meson.build. -build_dynamic_modules = false -dynamic_modules = get_option('dynamic-modules') -if dynamic_modules - gmodule_supported = dependency('gmodule-no-export-2.0').get_pkgconfig_variable('gmodule_supported') - if gmodule_supported == 'true' - build_dynamic_modules = true - else - message('Modules are not supported according to gmodule-no-export-2.0.pc') - endif -endif - -all_immodules = backend_immodules - -# Allow building some or all immodules included -included_immodules = get_option('included-immodules').split(',') -if included_immodules.contains('none') - included_immodules = [] -elif included_immodules.contains('all') - included_immodules = all_immodules -endif - -have_included_immodules = included_immodules.length() > 0 - -foreach im: included_immodules - if not all_immodules.contains(im) - error('The specified input method "@0@" is not available (available methods: @1@)'.format(im, ', '.join(all_immodules))) - endif -endforeach - -immodules_subdir = 'gtk-4.0/@0@/immodules'.format(gtk_binary_version) -immodules_install_dir = join_paths(gtk_libdir, immodules_subdir) - -# Format: -# - protocol name -# - protocol stability ('stable' or 'unstable') -# - protocol version (if stability is 'unstable') -proto_sources = [ - ['gtk-text-input', 'stable', ], -] - -im_wayland_gen_headers = [] -im_wayland_sources = files('imwayland.c') -wayland_scanner = find_program('wayland-scanner') -genprotocols = find_program('../../gdk/wayland/genprotocolfiles.py') - -foreach p: proto_sources - proto_name = p.get(0) - proto_stability = p.get(1) - - if proto_stability == 'stable' - output_base = proto_name - input = '@0@.xml'.format(proto_name) - else - proto_version = p.get(2) - output_base = '@0@-@1@-@2@'.format(proto_name, proto_stability, proto_version) - input = join_paths(proto_dir, '@0@/@1@/@2@.xml'.format(proto_stability, proto_name, output_base)) - endif - - im_wayland_sources += custom_target('@0@ client header'.format(output_base), - input: input, - output: '@0@-client-protocol.h'.format(output_base), - command: [ - genprotocols, - wayland_scanner, - '@INPUT@', '@OUTPUT@', - 'client-header', - ]) - - im_wayland_sources += custom_target('@0@ source'.format(output_base), - input: input, - output: '@0@-protocol.c'.format(output_base), - command: [ - genprotocols, - wayland_scanner, - '@INPUT@', '@OUTPUT@', - 'code', - ]) -endforeach - -method_defs = [ - ['broadway', files('imbroadway.c')], - ['quartz', ('imquartz.c'), [], ('-xobjective-c')], - ['xim', files('gtkimcontextxim.c')], - ['ime', files('gtkimcontextime.c'), ['imm32']], - ['wayland', im_wayland_sources], -] - -inc_im_method_defs = [] -dyn_im_method_defs = [] - -foreach m: method_defs - im = m.get(0) - srcs = m.get(1) - cargs = m.get(3, []) - libs = [] - - # only use backend-specific input methods for backends that are enabled - if all_immodules.contains(im) - # check for extra libs lazily - foreach libname: m.get(2, []) - libs += [cc.find_library(libname)] - endforeach - - if included_immodules.contains(im) - cdata.set('INCLUDE_IM_@0@'.format(im.underscorify()), true) - inc_im_method_defs += [[im, srcs, cargs, libs]] - elif build_dynamic_modules - dyn_im_method_defs += [[im, srcs, cargs, libs]] - endif - endif -endforeach diff --git a/modules/meson.build b/modules/meson.build index d0c4adc81d..cde966a094 100644 --- a/modules/meson.build +++ b/modules/meson.build @@ -1,5 +1,3 @@ -# Note: 'input' subdir has already been included from top-level. - if os_unix subdir('printbackends') endif -- 2.30.2